package com.obelisco.vista.componentes;

import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.TooManyListenersException;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;

import tucana.echo2.app.FileUploadSelector;
import tucana.echo2.app.fileuploader.ProgressBar;
import tucana.echo2.app.fileuploader.UploadCallback;

import com.obelisco.vista.estilos.Styles;
import com.obelisco.vista.imagen.ByteArrayImageReference;

//import net.sf.ehcache.util.PropertyUtil;
import nextapp.echo2.app.Alignment;
import nextapp.echo2.app.ApplicationInstance;
import nextapp.echo2.app.AwtImageReference;
import nextapp.echo2.app.Border;
import nextapp.echo2.app.Button;
import nextapp.echo2.app.Color;
import nextapp.echo2.app.Column;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.Grid;
import nextapp.echo2.app.ImageReference;
import nextapp.echo2.app.Insets;
import nextapp.echo2.app.Label;
import nextapp.echo2.app.ResourceImageReference;
import nextapp.echo2.app.StreamImageReference;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;
import nextapp.echo2.app.filetransfer.UploadEvent;
import nextapp.echo2.app.filetransfer.UploadListener;
import nextapp.echo2.app.filetransfer.UploadSelect;
import nextapp.echo2.app.layout.ColumnLayoutData;
import echopointng.ContainerEx;
import echopointng.ExtentEx;
import echopointng.ImageMap;
import echopointng.image.ImageKit;

public class PaneImagen extends ContainerEx {

	private ImageMap imgMapFoto;
	private ImageReference imgRefFoto;
	private int ancho = 150;
	private int alto = 150;

	public PaneImagen() {
		super();
		// Add design-time configured components.
		initComponents();
	}

	private void initComponents() {
		this.setWidth(new Extent(ancho, Extent.PX));
		this.setHeight(new Extent(alto, Extent.PX));
		Column column1 = new Column();
		add(column1);
		
		imgMapFoto = new ImageMap();
		imgRefFoto = Styles.ICON_NOFOTO;
		imgMapFoto.setImage(imgRefFoto);
		column1.add(imgMapFoto);

	}

	public int getAlto() {
		return alto;
	}

	public void setAlto(int alto) {
		this.alto = alto;
		this.setHeight(new Extent(alto, Extent.PX));
		this.imgMapFoto.setHeight(new Extent(alto, Extent.PX));
	}

	public int getAncho() {
		return ancho;
	}

	public void setAncho(int ancho) {
		this.ancho = ancho;
		this.setWidth(new Extent(ancho, Extent.PX));
		this.imgMapFoto.setWidth(new Extent(ancho, Extent.PX));
	}


	private void setImgRefFoto(ImageReference imgRefFoto) {
		this.imgRefFoto = imgRefFoto;
		imgMapFoto.setImage(this.imgRefFoto);
	}

	public void setImagen(byte[] data, String contentType) {
		if (data != null) {
			if (data.length > 0) {
	            setImgRefFoto(new ByteArrayImageReference(data,contentType));
	            this.setAncho(ancho);
	            this.setAlto(alto);
	        } else {
	        	setImgRefFoto(Styles.ICON_NOFOTO);	
	            this.setAncho(ancho);
	            this.setAlto(alto);

	        }
		}else {
        	setImgRefFoto(Styles.ICON_NOFOTO);	
            this.setAncho(ancho);
            this.setAlto(alto);

		}
		
	}

}

